/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: HP
 * Date: 2023 -04 -04
 * Time: 22:07
 */
class ThreeContinuousDigit {
    private int[] arrayIndexs;//下标
    private int[] numbers;//长度
    private int sunArrayNumber;//有效个数
    private int[] sorceArray;//原始数组

    public ThreeContinuousDigit(int[] array) {
        sorceArray = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            sorceArray[i] = array[i];
        }
        arrayIndexs = new int[array.length];
        numbers = new int[array.length];
        sunArrayNumber = 0;
    }

    public ThreeContinuousDigit(int[] arrayIndexs, int[] numbers, int sunArrayNumber, int[] sorceArray) {
        this.arrayIndexs = arrayIndexs;
        this.numbers = numbers;
        this.sunArrayNumber = sunArrayNumber;
        this.sorceArray = sorceArray;

    }

    public ThreeContinuousDigit locationContinuousDigit() {

        for (int i = 0; i < sorceArray.length; i++) {//确定子数组起始位置
            for (int j = 1; j <= (sorceArray.length - i) / 3; j++) {//确定子数组长度
                //[i,i+j-1]
                int cnt = 1;
                for (int k = i + j; k <= sorceArray.length - j; k += j) {//比较数组起始位置
                    boolean flg = true;
                    for (int l = 0; l < j; l++) {
                        if (sorceArray[i + l] != sorceArray[k + l]) {
                            flg = false;
                            break;
                        }
                    }
                    if (flg) {
                        cnt++;
                        if (cnt >= 3) {
                            arrayIndexs[sunArrayNumber] = i;
                            numbers[sunArrayNumber] = j;
                            sunArrayNumber++;
                        }
                    } else {
                        break;
                    }
                }

            }
        }
        return new ThreeContinuousDigit(arrayIndexs, numbers, sunArrayNumber, sorceArray);
    }

    public int[] getArrayIndexs() {
        return arrayIndexs;
    }

    public int[] getNumbers() {
        return numbers;
    }

    public int getSunArrayNumber() {
        return sunArrayNumber;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 2, 3, 4, 2, 3, 4, 3, 3, 3, 4, 3, 4, 3, 4, 5, 5, 5};
        ThreeContinuousDigit tcd = new ThreeContinuousDigit(arr);
        tcd.locationContinuousDigit();
        int[] index = tcd.getArrayIndexs();
        int[] number = tcd.getNumbers();
        int len = tcd.getSunArrayNumber();
        for (int i = 0; i < len; i++) {
            System.out.print(index[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < len; i++) {
            System.out.print(number[i] + " ");
        }
        System.out.println();
    }
}

